﻿package com.wly.adapter
{
	import com.wly.adapter.common.AdapterBase;
	import com.wly.ui.MapArea;
	
	public class MapAreaAdapter extends AdapterBase
	{
		private var _cellStatus:Array = [];
		private var _curWork:int;
		
		static public const EDIT_MAP:int = 0;
		static public const EDIT_ROAD:int = 1;
		
		static public const STAT_CELL_VALID:int = 1;
		static public const STAT_CELL_UNVALID:int = 0;
		
		public function MapAreaAdapter()
		{
			super();
		}
		
		public function get roadStr():String
		{
			var i:int;
			var val:int;
			var roadInfo:String;
			for(i=0; i<_cellStatus.length; i++)
			{
				val = _cellStatus[i] as int;
				if(val == 1)
				{
					if(!roadInfo)
					{
						roadInfo = i.toString();
					}
					else
					{
						roadInfo += ","+i.toString();
					}
				}
			}
			return roadInfo;
		}
		
		protected function get uiMapArea():MapArea
		{
			return ui as MapArea;
		}
		
		public function ChgCellStat(index:int):void
		{
			var stat:int = _cellStatus[index];
			
			if(stat == STAT_CELL_VALID)
			{
				_cellStatus[index] = STAT_CELL_UNVALID;
			}
			else
			{
				_cellStatus[index] = STAT_CELL_VALID;
			}
			uiMapArea.setRoadCellStat(index);
		}
		
		public function getCellStatus():Array
		{
			return _cellStatus;
		}
		
		public function clearAllCellStatus():void
		{
			_cellStatus = [];
			if(ui)
			{
				uiMapArea.updateWorkStat(_curWork);
			}
		}
		
		public function set workStatus(stat:int):void
		{
			_curWork = stat;
			if(ui)
			{
				uiMapArea.updateWorkStat(_curWork);
			}
		}
		
		public function switchWorkStat():void
		{
			if(_curWork == EDIT_MAP)
			{
				_curWork = EDIT_ROAD;
			}
			else if(_curWork == EDIT_ROAD)
			{
				_curWork = EDIT_MAP;
			}
			
			if(ui)
			{
				uiMapArea.updateWorkStat(_curWork);
			}
		}
		
		public function get workStatus():int
		{
			return _curWork;
		}
	}
}